import hashlib
import json


def sha1_hash_data(data):
    """计算对象的md5"""
    json_data = json.dumps(data)
    sha1_hash = hashlib.sha1(json_data.encode('utf-8'))
    return sha1_hash.hexdigest()


def sha1_hash_file(file_path):
    """计算文件的md5"""
    sha1_hash = hashlib.sha1()
    with open(file_path,'rb') as fobj:
        while True:
            data = fobj.read(4096)
            if not data:
                break
            sha1_hash.update(data)
    return sha1_hash.hexdigest()